package org.wmq.skyserver.controller.user;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wmq.skycommon.context.BaseContext;
import org.wmq.skycommon.pojo.DTO.ShoppingCartDTO;
import org.wmq.skycommon.pojo.entity.Result;
import org.wmq.skycommon.pojo.entity.ShoppingCart;
import org.wmq.skyserver.service.ShoppingCartService;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api("C端购物车接口")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        this.shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result list(){
        List<ShoppingCart> list = this.shoppingCartService.showShoppingCart(BaseContext.getCurrentId());
        return Result.success(list);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result delete(){
        this.shoppingCartService.clean(BaseContext.getCurrentId());
        return Result.success();
    }
}
